
package com.compuvest.tld;

// <editor-fold defaultstate="collapsed" desc="import">
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;

import com.compuvest.web.Basket;

import java.text.DecimalFormat;
// </editor-fold>

public class Head extends TagSupport {

// <editor-fold defaultstate="collapsed" desc="doStartTag()">

    @Override
    public int doStartTag() throws JspException {

        StringBuilder out = new StringBuilder(2200);
        String https = pageContext.getServletContext().getInitParameter("https");
        String http = pageContext.getServletContext().getInitParameter("http");
        String info = pageContext.getServletContext().getInitParameter("info");
        Basket basket = (Basket)pageContext.getSession().getAttribute("basket");

        out.append("<div id='cvhead'>");

        out.append("<table id='mnhead'>");
        out.append("<tr height='70'>");
        out.append("<td valign='bottom'>");
        out.append("<a href='").append(http).append("'><img src='../img/hd/hlogo.png' border='0' alt='Compuvest.com'/></a>&nbsp;&nbsp;");
        out.append("<span id='bchat'></span>");
        out.append("<span><a href='").append(http).append("info/Amazon.jsp'><img src='../img/amazonhelp.png' alt='Amazon Checkout' style='border:0;margin-left:5px;'/></a></span>");
        out.append("</td>");
        out.append("<td align='right'>");
        out.append("<div style='padding-right:13px;'>");
        if(basket.notEmpty()) {
            out.append("<a href='").append(http).append("Basket.jsp' class='lnk'><b style='color:red;'>View Cart</b></a>");
        }
        else {
            out.append("<span class='lnk'>&nbsp;View Cart</span>");
        }
        out.append("&nbsp;|&nbsp;<a href='").append(https).append("CustomerForm.jsp' class='lnk'><font color='blue'>My Account</font></a>&nbsp;|&nbsp;");
        out.append("<a href='").append(https).append("ResellerForm.jsp' class='lnk'>");
        out.append("<font color='blue'>Reseller ").append((basket.getCustomer() != null && basket.getReseller()) ? "Items" : "Account").append("</font></a>&nbsp;|&nbsp;");
        if(basket.getCustomer() != null) {
            out.append("<a href='").append(http).append("CustomerForm.jsp?log=out' class='lnk'>Sign Out</a>");
        }
        else {
            out.append("<a href='").append(https).append("CustomerForm.jsp' class='lnk'>Sign In</a>");
        }
        out.append("<p class='lnk' style='padding-top:10px;'>");
        out.append((basket.getCustomer() != null && basket.getReseller()) ? "Reseller:" : "User:");
        out.append("<font color='#800000'>&nbsp;").append(basket.getCustomer() == null ? "Guest" : basket.getCustomer().getBillingAddress().getName()).append("</font>&nbsp;|&nbsp;");
        out.append("Items: <font color='#800000'>").append(basket.getCountItems()).append("</font>,&nbsp;");
        out.append("Total: <font color='#800000'>").append(new DecimalFormat("$#,##0.00").format(basket.getTotal(true))).append("</font>");
        out.append("</p>");
        out.append("</div>");
        out.append("</td>");
        out.append("</tr>");
        out.append("<tr height='30'>");
        out.append("<td colspan='2' align='center'>");
        out.append("<table>");
        out.append("<tr>");
        out.append("<td width='20%'>&nbsp;</td>");
        out.append("<td><span id='hsocial'></span></td>");
        out.append("<td><a class='btgr hbl1' href='").append(http).append("'><b>All Products</b></a></td>");
        out.append("<td><a class='btgr hbl2' href='").append(http).append("Cats.jsp?cid=573'>Notebooks,<br/>PDAs</a></td>");
        out.append("<td><a class='btgr hbl1' href='").append(http).append("Cats.jsp?cid=5'>Networking</a></td>");
        out.append("<td><a class='btgr hbl1' href='").append(http).append("Cats.jsp?cid=13'>Printers</a></td>");
        out.append("<td><a class='btgr hbl1' href='").append(http).append("Cats.jsp?cid=474'>Electronics</a></td>");
        out.append("<td><a class='btgr hbl1' href='").append(http).append("Cats.jsp?cid=16'>Cameras</a></td>");
        out.append("<td><a class='btgr hbl1' href='").append(http).append("Cats.jsp?cid=446'>Computers</a></td>");
        out.append("<td><a class='btgr hbl1' href='").append(http).append("Cats.jsp?cid=403'>Software</a></td>");
        out.append("<td><a class='btyw hbl2' href='").append(http).append("ItemsSpecial.jsp?cp=2'>Weekly<br/>Specials</a></td>");
        out.append("<td><a class='btpn hbl1' href='").append(http).append("ItemsClearance.jsp?cp=11'>Clearance</a></td>");
        out.append("<td><a class='btgn hbl2' href='").append(http).append("ItemsBrand.jsp?cp=3'>Shop by<br/>Brand</a></td>");
        out.append("<td><a class='btgn hbl2' href='").append(info).append("ProductRequest.jsp'>Product<br/>Request</a></td>");
        //out.append("<td><a class='btgn hbl2' href='").append(info).append("OnSiteServices.jsp'>Service<br/>Request</a></td>");
        out.append("<td width='20%'>&nbsp;</td>");
        out.append("</tr>");
        out.append("</table>");
        out.append("</td>");
        out.append("</tr>");
        out.append("</table>");

        out.append("</div>\n");
        out.append("<div id='dsrch'>&nbsp;</div>\n"); // for search tag

        try {
            pageContext.getOut().print(out.toString());
        }
        catch(java.io.IOException e) {
            throw new JspTagException("com.compuvest.tgl.Head:doStartTag() " + e.getMessage());
        }

        return SKIP_BODY;
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="doEndTag()">

    @Override
    public int doEndTag() {
        return EVAL_PAGE;
    }
// </editor-fold>

}
